from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from datetime import datetime

Base = declarative_base()


class User(Base):
    __tablename__ = 'user'
    user_id = Column(Integer, primary_key=True, index=True)
    username = Column(String, unique=True, index=True)
    password = Column("password", String)


class Conversation(Base):
    __tablename__ = 'conversation'
    conversation_id = Column(String, primary_key=True, index=True)
    user_id = Column(Integer, ForeignKey('user.user_id'))
    timestamp = Column(DateTime, default=datetime.now)
    user = relationship("User")


class ChatMessage(Base):
    __tablename__ = 'chat_messages'
    message_id = Column(Integer, primary_key=True, index=True)
    user_id = Column(String)
    conversation_id = Column(String, ForeignKey('conversation.conversation_id'))
    message_content = Column(String)
    sender = Column(String)
    timestamp = Column(DateTime, default=datetime.now)
    conversation = relationship("Conversation")
